//
//  CGQxiangmuCell.swift
//  SheYangBigData
//
//  Created by 叁拾叁 on 2021/4/7.
//  Copyright © 2021 叁拾叁. All rights reserved.
//


import UIKit


class CGQxiangmuCell: SYBaseCell {


    
    var bgView: UIView = {
        let v = UIView()
        v.backgroundColor = UIColor.white
        v.layer.cornerRadius = 5.autoWidth()
        v.layer.masksToBounds = true
        return v
    }()
    
    let title: UILabel = {
        let v:UILabel = UILabel()
        v.textColor = UIColor(hex: 0x333333)
        v.font = 17.autoBoldFontSize()
        v.text = "设备离线"
        v.numberOfLines = 0
        return v
    }()
    
    let pic: UIImageView = {
        let v: UIImageView = UIImageView()
        v.sy_name("xiangmu_icon")
        return v
    }()
    
    let arrow: UIImageView = {
        let v: UIImageView = UIImageView()
        v.sy_name("arrow_gray")
        return v
    }()
    
    let xiangmu: CGQXiangmuView = CGQXiangmuView()
    
    let shebei: CGQXiangmuShebeiView = CGQXiangmuShebeiView()
    
    var xiangmuBt: UIButton = {
        let v = UIButton()
        return v
    }()
    

    public func configureView(model: NSRecordsModel) {
//        title.text = model.name
//        if let p = model.imgPath {
//            pic.kf.setImage(with: URL(string: IMGIP+p))
//        }
        title.text = model.appName
        xiangmu.num.text = "\(model.childAppSize)"
        shebei.num.text = "\(model.childDeviceSize )"
        
        
        xiangmuBt.addAction {[weak self] in
            if let `self` = self {
//                let  vc =  CGQxiangmuGuanliVC(id: model.id!)
//
//                self.currentVC.sy_push(vc)
                
                
                
                let  vc =  CGQxiangmuGuanliVC(id: model.id ?? "")
                
                self.currentVC.sy_push(vc)
                
            }
        }
         shebei.xiangmuBt.addAction {[weak self] in
            if let `self` = self {
//                let vc = CGQShebeiListViewController()
//                self.currentVC.sy_push(vc)
                
                self.passParamsClosure!(model)

            }
        }
        xiangmu.xiangmuBt.addAction {[weak self] in
            if let `self` = self {
//                let vc = CGQxiangmuChoiceListViewController()//CGQxiangmuListViewController()
//                self.currentVC.sy_push(vc)
            }
        }
    }
    
    override func initViews() {
        
        self.backgroundColor = .clear
        contentView.addSubview(bgView)
        contentView.addSubview(pic)
        contentView.addSubview(title)
        contentView.addSubview(arrow)
        contentView.addSubview(xiangmu)
        contentView.addSubview(shebei)
        contentView.addSubview(lineView)
        contentView.addSubview(xiangmuBt)
        bgView.snp.makeConstraints { (make) in
            make.top.equalToSuperview().offset(10.autoWidth())
            make.left.equalToSuperview().offset(autoWidth(10))
            make.right.equalToSuperview().offset(autoWidth(-10))
            make.bottom.equalToSuperview()
        }

        title.snp.makeConstraints { (make) in
            make.top.equalToSuperview().offset(22.autoWidth())
            make.left.equalToSuperview().offset(autoWidth(43))
            make.right.equalToSuperview().offset(autoWidth(-30.0))
//            make.height.equalTo(15.autoWidth())

        }
        pic.snp.makeConstraints { (make) in
            make.left.equalToSuperview().offset(autoWidth(20))
            make.width.equalTo(18.autoWidth())
            make.height.equalTo(18.autoWidth())
            make.centerY.equalTo(title.snp.centerY)
//            make.bottom.equalToSuperview().offset(-80.autoWidth())
        }
        lineView.snp.makeConstraints { (make) in
            make.top.equalTo(title.snp.bottom).offset(12.autoWidth())
            make.left.equalToSuperview().offset(autoWidth(10))
            make.right.equalToSuperview().offset(autoWidth(-10.0))
            make.height.equalTo(0.5.autoWidth())
//            make.bottom.equalToSuperview().offset(-10.autoWidth())
        }
        
        arrow.snp.makeConstraints { (make) in
            make.right.equalToSuperview().offset(autoWidth(-20.0))
            make.width.equalTo(8.autoWidth())
            make.height.equalTo(14.autoWidth())
            make.centerY.equalTo(title.snp.centerY)
            
        }
        xiangmuBt.snp.makeConstraints { (make) in
            make.left.equalToSuperview()
            make.right.equalToSuperview()
            make.height.equalTo(40.autoWidth())
        }
       
        xiangmu.snp.makeConstraints { (make) in
            make.top.equalTo(lineView.snp.bottom).offset(12.autoWidth())
            make.left.equalToSuperview().offset(20.autoWidth())
            make.width.equalTo(162.autoWidth())
            make.height.equalTo(45.autoWidth())
            make.bottom.equalToSuperview().offset(-10.autoWidth())
        }
        
        
        shebei.snp.makeConstraints { (make) in
            make.centerY.equalTo(xiangmu.snp.centerY)
            make.right.equalToSuperview().offset(-20.autoWidth())
            make.width.equalTo(162.autoWidth())
            make.height.equalTo(45.autoWidth())
        }

    }
}


class CGQXiangmuView: SYBaseView {
    
    var title: UILabel = {
        let v = UILabel()
        v.text = "子项目数(个)："
        v.font = 14.autoFontSize()
        v.textColor = UIColor(hex: 0x0782FF)
        return v
    }()
    
    let num: UILabel = {
        let v = UILabel()
        v.text = "0"
        v.font = 24.autoBoldFontSize()
        v.textColor = UIColor(hex: 0x0782FF)
        return v
    }()
    
    var xiangmuBt: UIButton = {
        let v = UIButton()
        return v
    }()
    
    override func initViews() {
        
       
        self.layer.cornerRadius = 5.autoWidth()
        self.layer.masksToBounds = true
        self.backgroundColor = UIColor(hex: 0xE6F2FF)
        addSubview(title)
        addSubview(num)
        addSubview(xiangmuBt)
        title.snp.makeConstraints { (make) in
            make.centerY.equalToSuperview()
            make.left.equalToSuperview().offset(11.autoWidth())
            make.height.equalTo(14.autoWidth())
        }
        num.snp.makeConstraints { (make) in
            make.centerY.equalToSuperview()
            make.right.equalToSuperview().offset(-16.autoWidth())
            make.height.equalTo(18.autoWidth())
        }
       
        xiangmuBt.snp.makeConstraints { (make) in
            make.edges.equalToSuperview()
        }
    }
}


class CGQXiangmuShebeiView: SYBaseView {
    
    let title: UILabel = {
        let v = UILabel()
        v.text = "子设备数(个)："
        v.font = 14.autoFontSize()
        v.textColor = UIColor(hex: 0x0782FF)
        return v
    }()
    
    let num: UILabel = {
        let v = UILabel()
        v.text = "0"
        v.font = 24.autoBoldFontSize()
        v.textColor = UIColor(hex: 0x0782FF)
        return v
    }()
    
    let imgView: UIImageView = {
        let v = UIImageView()
        v.image = UIImage(named: "arrow_xiangmu")
        return v
    }()
    
    var xiangmuBt: UIButton = {
        let v = UIButton()
        return v
    }()
    
    override func initViews() {
        
        
        self.layer.cornerRadius = 5.autoWidth()
        self.layer.masksToBounds = true
        self.backgroundColor = UIColor(hex: 0xE6F2FF)
        addSubview(title)
        addSubview(num)
        addSubview(imgView)
        addSubview(xiangmuBt)
        title.snp.makeConstraints { (make) in
            make.centerY.equalToSuperview()
            make.left.equalToSuperview().offset(11.autoWidth())
            make.height.equalTo(14.autoWidth())
        }
        num.snp.makeConstraints { (make) in
            make.centerY.equalToSuperview()
            make.right.equalTo(imgView.snp.left).offset(-5.autoWidth())
            make.height.equalTo(18.autoWidth())
        }
        imgView.snp.makeConstraints { (make) in
            make.centerY.equalToSuperview()
            make.right.equalToSuperview().offset(-7.autoWidth())
            make.height.equalTo(14.autoWidth())
        }
        xiangmuBt.snp.makeConstraints { (make) in
            make.edges.equalToSuperview()
        }
    }
}
